{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<style>
    .layui-form-label {
        width: 200px !important;
    }
    .layui-input-block {
        margin-left: 200px !important;
    }
</style>
{php}$level = model('user_level')->where('status',1)->order('id asc')->select();{/php}
<form class="layui-form p-4">
	<h3 class="pb-3">权限设置</h3>
    <div class="py-3">
        <div class="layui-card layui-form-pane">
            <div class="layui-card-header">用户设置</div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启注册</label>
                        <div class="layui-input-block">
                            {if(!isset($config['register_open']))}
                                <input type="radio" name="register_open" value="1" title="开启" checked>
                                <input type="radio" name="register_open" value="0" title="关闭">
                            {else/}
                                <input type="radio" name="register_open" value="1" title="开启"{eq name="$config.register_open" value="1"} checked{/eq}>
                                <input type="radio" name="register_open" value="0" title="关闭"{eq name="$config.register_open" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>                
                    <div class="layui-form-item">
                        <label class="layui-form-label">允许登录类型</label>
                        <div class="layui-input-block">
                            {empty name="$config.login_type"}
                                <input type="checkbox" name="login_type[]" value="sms" title="短信登录">
                                <input type="checkbox" name="login_type[]" value="account" title="账号登录">
                                {volist name=":get_addons_type('login')" id="v"}
                                    <input type="checkbox" name="login_type[]" value="{$v.name}" title="{$v.title}">
                                {/volist}
                            {else/}
                                <input type="checkbox" name="login_type[]" value="sms" title="短信登录" {if(in_array('sms', $config['login_type']))}checked{/if}>
                                <input type="checkbox" name="login_type[]" value="account" title="账号登录" {if(in_array('account', $config['login_type']))}checked{/if}>
                                {volist name=":get_addons_type('login')" id="v"}
                                    <input type="checkbox" name="login_type[]" value="{$v.name}" title="{$v.title}" {if(in_array($v['name'], $config['login_type']))}checked{/if}>
                                {/volist}
                            {/empty}
                        </div>
                        <div class="layui-form-mid layui-text-em">登录插件安装启用后需要在这里设置开启才会有效，如全未勾选则表示禁止登录。</div>
                    </div>
                </div>                
            </div>
            <hr>
            <div class="layui-card-header">阅读设置</div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启登录阅读</label>
                        <div class="layui-input-block">
                            {if(!isset($config['login_read_open']))}
                                <input type="radio" name="login_read_open" value="1" title="是">
                                <input type="radio" name="login_read_open" value="0" title="否" checked>
                            {else/}
                                <input type="radio" name="login_read_open" value="1" title="是"{eq name="$config.login_read_open" value="1"} checked{/eq}>
                                <input type="radio" name="login_read_open" value="0" title="否"{eq name="$config.login_read_open" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">前多少章不需要登录</label>
                        <div class="layui-input-inline layui-input-wrap">
                          <input type="text" name="login_read_num" value="{$config.login_read_num|default='0'}" placeholder="请填写章节数" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-text-em">开启登录阅读后此项才会生效，为0或空则表示所有章节都需要登录后才能阅读。</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">阅读收费模式</label>
                        <div class="layui-input-inline" style="min-width: 300px;">
                            {if(!isset($config['charge_read_type']))}
                                <input type="checkbox" name="charge_read_type[]" value="free" title="免费" checked lay-filter="free">
                                <input type="checkbox" name="charge_read_type[]" value="vip" title="会员" lay-filter="userlevel">
                                <input type="checkbox" name="charge_read_type[]" value="coin" title="金币" lay-filter="coin">
                            {else/}
                                <input type="checkbox" name="charge_read_type[]" value="free" title="免费" {if(in_array('free', $config['charge_read_type']))}checked{/if} lay-filter="free">
                                <input type="checkbox" name="charge_read_type[]" value="vip" title="会员" {if(in_array('vip', $config['charge_read_type']))}checked{/if} lay-filter="userlevel">
                                <input type="checkbox" name="charge_read_type[]" value="coin" title="金币" {if(in_array('coin', $config['charge_read_type']))}checked{/if} lay-filter="coin">
                            {/if}
                        </div>
                        <div class="layui-form-mid layui-word-aux">免费模式为全站免费，会员模式需购买VIP会员，金币模式用于消耗金币阅读，<br>会员模式与金币模式同时开启时，优先使用会员模式，不是会员则使用金币模式，免费模式不可与其他模式共存，<br>免费模式优先于其他模式，非免费模式时登录免费阅读则无效。</div>
                    </div>
                    <div class="layui-form-item userlevel" {if(!isset($config.charge_read_type) || !in_array('vip', $config['charge_read_type']) || in_array('free', $config['charge_read_type']))}style="display: none;"{/if}>
                         <label class="layui-form-label">选择会员级别</label>
                         <div class="layui-input-block">
                            {empty name="$config.userlevel"}
                                {volist name="$level" id="v"}
                                    <input type="checkbox" name="userlevel[]" value="{$v.id}" title="{$v.title}">
                                {/volist}
                            {else/}
                                {volist name="$level" id="v"}
                                    <input type="checkbox" name="userlevel[]" value="{$v.id}" title="{$v.title}" {if(in_array($v['id'], $config['userlevel']))}checked{/if}>
                                {/volist}
                            {/empty}
                         </div>
                    </div>
                    <div class="coin" {if(!isset($config.charge_read_type) || !in_array('coin', $config['charge_read_type']) || in_array('free', $config['charge_read_type']))}style="display: none;"{/if}>        
                        <div class="layui-input-inline layui-input-wrap">
                            {if $level}
                                {volist name="$level" id="v"}
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">{$v.title}千字金币</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="read_thousand_price[{$v.id}]" autocomplete="off" value="{$config['read_thousand_price'][$v['id']]|default='0'}" placeholder="请填写{$v.title}千字金币" class="layui-input read_thousand_price">
                                        </div>
                                    </div>
                                {/volist}
                            {else/}
                                <input type="text" name="read_thousand_price" value="{$config.read_thousand_price|default='0'}" placeholder="请填写千字金币" autocomplete="off" class="layui-input">
                            {/if}
                        </div>
                        <div class="layui-form-item">此处设置仅对金币模式有效，如果价格为0，则等于会员模式。</div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">前多少章免费</label>
                            <div class="layui-input-inline layui-input-wrap">
                            <input type="text" name="front_free_chapter_num" value="{$config.front_free_chapter_num|default='0'}" placeholder="请填写章节数" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-text-em">此章节数仅对金币模式有效，为0则表示所有章节不免费。</div>
                        </div>
                    </div>
                </div>                
            </div>
            <hr>
            <div class="layui-card-header">下载设置</div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启TXT下载</label>
                        <div class="layui-input-block">
                            {if(!isset($config['txt_download_open']))}
                                <input type="radio" name="txt_download_open" value="1" title="是">
                                <input type="radio" name="txt_download_open" value="0" title="否" checked>
                            {else/}
                                <input type="radio" name="txt_download_open" value="1" title="是"{eq name="$config.txt_download_open" value="1"} checked{/eq}>
                                <input type="radio" name="txt_download_open" value="0" title="否"{eq name="$config.txt_download_open" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">最多可下载章节数</label>
                        <div class="layui-input-inline layui-input-wrap">
                          <input type="text" name="txt_download_num" value="{$config.txt_download_num|default='0'}" placeholder="请填写章节数" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-text-em">开启TXT下载后此项才会生效，为0或空则表示下载所有章节。</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">下载是否必须登录</label>
                        <div class="layui-input-block">
                            {if(!isset($config['txt_download_islogin']))}
                                <input type="radio" name="txt_download_islogin" value="1" title="是" checked>
                                <input type="radio" name="txt_download_islogin" value="0" title="否">
                            {else/}
                                <input type="radio" name="txt_download_islogin" value="1" title="是"{eq name="$config.txt_download_islogin" value="1"} checked{/eq}>
                                <input type="radio" name="txt_download_islogin" value="0" title="否"{eq name="$config.txt_download_islogin" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推广内容添加方式</label>
                        <div class="layui-input-block">
                            {empty name="$config.txt_download_promotion_type"}
                                <input type="radio" name="txt_download_promotion_type" value="0" title="不添加" checked>
                                <input type="radio" name="txt_download_promotion_type" value="1" title="头部添加">
                                <input type="radio" name="txt_download_promotion_type" value="2" title="尾部添加">
                                <input type="radio" name="txt_download_promotion_type" value="3" title="头尾添加">
                                <input type="radio" name="txt_download_promotion_type" value="4" title="每章添加">
                            {else/}
                                <input type="radio" name="txt_download_promotion_type" value="0" title="不添加"{eq name="$config.txt_download_promotion_type" value="0"} checked{/eq}>
                                <input type="radio" name="txt_download_promotion_type" value="1" title="头部添加"{eq name="$config.txt_download_promotion_type" value="1"} checked{/eq}>
                                <input type="radio" name="txt_download_promotion_type" value="2" title="尾部添加"{eq name="$config.txt_download_promotion_type" value="2"} checked{/eq}>
                                <input type="radio" name="txt_download_promotion_type" value="3" title="头尾添加"{eq name="$config.txt_download_promotion_type" value="3"} checked{/eq}>
                                <input type="radio" name="txt_download_promotion_type" value="4" title="每章添加"{eq name="$config.txt_download_promotion_type" value="4"} checked{/eq}>
                            {/empty}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推广内容</label>
                        <div class="layui-input-block">
                            <textarea placeholder="支持换行与空格，和种特殊字符，不支持html标签。" name="txt_download_promotion_content" class="layui-textarea">{$config.txt_download_promotion_content|default=''}</textarea>
                        </div>
                    </div>
                </div>                
            </div>
            <hr>
            <div class="layui-card-header">作家设置</div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启作家功能</label>
                        <div class="layui-input-block">
                            {if(!isset($config['author_open']))}
                                <input type="radio" name="author_open" value="1" title="开启">
                                <input type="radio" name="author_open" value="0" title="关闭" checked>
                            {else/}
                                <input type="radio" name="author_open" value="1" title="开启"{eq name="$config.author_open" value="1"} checked{/eq}>
                                <input type="radio" name="author_open" value="0" title="关闭"{eq name="$config.author_open" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>
                </div>                
            </div>
            <hr>
            <div class="layui-card-header">其他设置</div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启举报功能</label>
                        <div class="layui-input-block">
                            {if(!isset($config['report_open']))}
                                <input type="radio" name="report_open" value="1" title="开启">
                                <input type="radio" name="report_open" value="0" title="关闭" checked>
                            {else/}
                                <input type="radio" name="report_open" value="1" title="开启"{eq name="$config.report_open" value="1"} checked{/eq}>
                                <input type="radio" name="report_open" value="0" title="关闭"{eq name="$config.report_open" value="0"} checked{/eq}>
                            {/if}
                        </div>
                    </div>
                </div>                
            </div>
        </div>
        <input type="hidden" name="id" value="{$id}">
		<button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function feiniaoInit() {
		var form = layui.form, tool = layui.tool;
        form.on('checkbox(free)', function(data) {
            if(data.elem.checked) {
				$('.userlevel, .coin').hide();
                $("input[lay-filter='userlevel'], input[lay-filter='coin']").each(function(){
                    this.checked = false;
                });
                $("input[name='userlevel[]']").prop('checked', false);
                $('.read_thousand_price').val(0);
                form.render();
			}
		});
        form.on('checkbox(userlevel)', function(data) {
            if(data.elem.checked) {
                $("input[lay-filter='free']").prop('checked', false);
                $('input[name=login_read_open][value=0]').prop('checked', true);
                form.render('radio');
                form.render('checkbox');
				$('.userlevel').show();
			} else {                
                $("input[name='userlevel[]']").prop('checked', false);
                form.render('checkbox');
				$('.userlevel').hide();
			}
		});
        form.on('checkbox(coin)', function(data) {
            if(data.elem.checked) {
                $("input[lay-filter='free']").prop('checked', false);
                $('input[name=login_read_open][value=0]').prop('checked', true);
                form.render('radio');
                form.render('checkbox');
				$('.coin').show();
			} else {
                $('.read_thousand_price').val(0);
                form.render();
				$('.coin').hide();
			}
		});
		//监听提交
		form.on('submit(webform)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					parent.layui.tool.close(1000);
				}
			}
			tool.post("{:url('conf/edit')}", data.field, callback);
			return false;
		});		
	}
</script>
{/block}
<!-- /脚本 -->